<script type="text/javascript">
	function ScoreDelayedCtrl(CtrlUtil, $http, $scope, modalService, $element) {
		var ctrl = this
		CtrlUtil.build(this, ':root/score/queryDelayed', $scope.ctrl)
		this.add = function() {
			var content = $element.find('[template]>[add]').clone()
			modalService.confirm({
				title : '添加成绩',
				content : content,
				search : {
					enable : true
				},
				result : {
					stuInfo : {}
				},
				ctrl : ctrl
			}).then(function(r) {
				$http.post(':root/score/addDelayed', r).success(function(R) {
					if (R) {
						modalService.succ('添加成功', 1500)
						ctrl.query()
					} else {
						modalService.error('添加失败', 1500)
					}
				})
			})
		}
		this.edit = function(item) {
			var content = $element.find('[template]>[add]').clone()
			modalService.confirm({
				title : '修改成绩',
				content : content,
				search : {
					enable : false,
					stuInfo : item.stuInfo
				},
				result : item,
				ctrl : ctrl
			}).then(function(r) {
				$http.post(':root/score/addDelayed', r).success(function(R) {
					if (R) {
						modalService.succ('修改成功', 1500)
						ctrl.query()
					} else {
						modalService.error('修改失败', 1500)
					}
				})
			})
		}
		this.searchStudent = function(name, target) {
			$http.post(':root/trainee/queryStudents', {
				name : name,
				pageSize : 9
			}).success(function(r) {
				target = target || ctrl
				target.students = r
			})
		}

		this.socreChange = function(result) {
			result.zj = (parseFloat(result.xzt || 0) + parseFloat(result.zgt || 0))
			result.khjg = (result.zj > 85 ? '优秀' : (result.zj > 75 ? '良好' : (result.zj > 60 ? '合格' : '不通过')))
		}
		this.import = function() {
			var content = $element.find('[import]').clone()
			var modal = modalService.show({
				title : '成绩导入',
				content : content,
				upload : function() {
					content.find('form').ajaxForm().ajaxSubmit({
						url : require.toUrl('root/score/importDelayed'),
						success : function(r) {
							if (r == '') {
								modalService.succ('导入成功', 1500)
							} else {
								modalService.succ('导入失败：' + r, 1500)
							}
							modal.close()
						},
						error : function() {
							modalService.error('导入失败', 1500)
						}
					});
				},
				term : ctrl.termQueryParam,
				supCtrl : $scope.ctrl
			}, {
				backdrop : false
			})
		}
	}
</script>
<div ng-controller="ScoreDelayedCtrl as subCtrl" ng-init="ctrl.subCtrl=subCtrl;ctrl.query()">
	<div class="">
		<button type="button" class="btn btn-cys btn-sm" ng-click="subCtrl.add()">
			<span class="glyphicon glyphicon-plus"></span>
			添加
		</button>
		<button type="button" class="btn btn-cys btn-sm" ng-click="subCtrl.import()">
			<span class="glyphicon glyphicon-import"></span>
			成绩导入
		</button>
		<button type="button" class="btn btn-cys btn-sm" ng-click="export(ctrl,'root/score/exportDelayed')">
			<span class="glyphicon glyphicon-export"></span>
			导出
		</button>
		<div ng-if="subCtrl" ng-init="ctrl=subCtrl" class="pull-right" ng-include="':root/components/page.html'"></div>
	</div>
	<!-- operation area END -->
	<!-- data grid area -->
	<div style="padding-top: 10px;">
		<table class="table table-bordered table-hover table-striped" ng-if="subCtrl" ng-init="ctrl=subCtrl">
			<tr>
				<th>
					<input ng-change="ctrl.checkAll(ctrl.$checkAll)" ng-model="ctrl.$checkAll" type="checkbox" />
				</th>
				<th>姓名</th>
				<th>性别</th>
				<th>学号</th>
				<th>院系</th>
				<!-- <th>专业</th> -->
				<th>所属班级</th>
				<th>职务</th>
				<th>选择题</th>
				<th>主观题</th>
				<th>总计</th>
				<th>操作</th>
			</tr>
			<tr ng-repeat="item in ctrl.entities.content">
				<td>
					<input ng-model="item.$checked" type="checkbox" />
				</td>
				<td>{{item.stuInfo.user.name}}</td>
				<td>{{item.stuInfo.sexString}}</td>
				<td>{{item.stuInfo.user.uid}}</td>
				<td>{{$root.departmentMap[item.stuInfo.user.department].name}}</td>
				<!-- <td>{{item.stuInfo.student.major.name}}</td> -->
				<td>{{item.stuInfo.classInfo.bjName}}</td>
				<td>{{item.stuInfo.zw}}</td>
				<td>{{item.xzt}}</td>
				<td>{{item.zgt}}</td>
				<td>{{item.zj}}</td>
				<td>
					<a href="javascript:;" class="remove-underline" ng-click="ctrl.edit(item)">编辑</a>
				</td>
			</tr>
		</table>
		<p ng-if="subCtrl">
			共有记录：
			<span>{{ctrl.entities.totalElements}}</span>
			条
		</p>
	</div>
	<div class="hidden" ng-non-bindable template>
		<div add>
			<form class="form-horizontal" single-student>
				<div class="form-group" ng-show="search.enable">
					<label class="col-md-2 control-label">学生</label>
					<div class="col-md-10 open">
						<input type="text" ng-change="ctrl.searchStudent(search.name,search)" ng-model="search.name" class="form-control"
							placeholder="按姓名/学号模糊搜索">
						<ul class="dropdown-menu" ng-show="search.students.content.length>0">
							<li ng-repeat="t in search.students.content">
								<a href="javascript:;" ng-click="search.stuInfo=t;result.stuInfo.id=t.id;search.students=null;">({{t.student.xh}}){{t.student.name}}</a>
							</li>
						</ul>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">姓名</label>
					<div class="col-md-4">
						<input type="text" ng-model="search.stuInfo.student.name" class="form-control" disabled="disabled">

					</div>
					<label class="col-md-2 control-label">性别</label>
					<div class="col-md-4">
						<input type="text" class="form-control" ng-model="search.stuInfo.student.sexString" disabled="disabled">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">学生类别</label>
					<div class="col-md-4">
						<input type="text" class="form-control" disabled="disabled" value="本科">
					</div>
					<label class="col-md-2 control-label">年级</label>
					<div class="col-md-4">
						<input type="text" class="form-control" ng-model="search.stuInfo.student.grade" disabled="disabled" value="2015">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">院系</label>
					<div class="col-md-4">
						<input type="text" class="form-control" disabled="disabled" ng-model="search.stuInfo.student.department.name">
					</div>
					<label class="col-md-2 control-label">专业</label>
					<div class="col-md-4">
						<input type="text" class="form-control" disabled="disabled" ng-model="search.stuInfo.student.major.name">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">校区</label>
					<div class="col-md-4">
						<input class="form-control" disabled="disabled" ng-model="search.stuInfo.xq">
					</div>
					<label class="col-md-2 control-label">联系电话</label>
					<div class="col-md-4">
						<input type="text" disabled="disabled" ng-model="search.stuInfo.lxfs" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">班级</label>
					<div class="col-md-4">
						<input class="form-control" disabled="disabled" ng-model="search.stuInfo.classInfo.bjName">
					</div>
					<label class="col-md-2 control-label">团支书</label>
					<div class="col-md-4">
						<span class="form-control" disabled="disabled" ng-bind="search.stuInfo.sfwtzs|toBool"></span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">备注</label>
					<div class="col-md-10">
						<input type="text" disabled="disabled" class="form-control" ng-model="search.stuInfo.bz">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">选择题</label>
					<div class="col-md-4">
						<input type="number" class="form-control" ng-model="result.xzt" ng-change="ctrl.socreChange(result)">
					</div>
					<label class="col-md-2 control-label">主观题</label>
					<div class="col-md-4">
						<input type="number" class="form-control" ng-model="result.zgt" ng-change="ctrl.socreChange(result)">
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">总计</label>
					<div class="col-md-4">
						<input class="form-control" ng-change="ctrl.socreChange(result)" ng-model="result.zj">
					</div>
					<label class="col-md-2 control-label">考核结果</label>
					<div class="col-md-4">
						<select class="form-control" ng-model="result.khjg">
							<option>优秀</option>
							<option>良好</option>
							<option>合格</option>
							<option>不通过</option>
						</select>
					</div>
				</div>
			</form>
		</div>
		<div import class="col-md-10 col-md-offset-1">
			<form class="form-horizontal" enctype="multipart/form-data" method="post">
				<div class="form-group">
					<div class="col-md-12 ">
						<select name="term" class="form-control" chosen ng-value="term">
							<option value="">期次</option>
							<option value="{{m.id}}" ng-selected="$index==0" ng-repeat="m in supCtrl.terms">{{(m.name+'-第'+m.qs+'期')}}</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<div class="col-md-12">
						<input class="form-control" id="fileImport" name="file" type="file" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-md-12">
						<a type="submit" ng-click="upload()" class="btn btn-success">导入</a>
						<a class="btn btn-link btn-sm" href="asset/excel/studenDelayedScoreSample.xls">
							<span class="glyphicon glyphicon-arrow-down"></span>
							导入模板下载
						</a>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>